/*
 * @lc app=leetcode.cn id=566 lang=javascript
 *
 * [566] 重塑矩阵
 */

// @lc code=start
/**
 * @param {number[][]} mat
 * @param {number} r
 * @param {number} c
 * @return {number[][]}
 */
var matrixReshape = function(mat, r, c) {
  let len1 = mat.length
  let len2 = mat[0].length
  if (len1 * len2 !== r * c) {
    return mat
  }
  let ary = Array(r).fill([]).map(() => Array(c).fill(0))
  for (let i = 0; i < len1 * len2; i++) {
    // for (let j = 0; j < len2; j++) {
      // ary[(n / c) | 0][n++ % c] = mat[i][j]
      ary[(i / c) | 0][i % c] = mat[(i / len2) | 0][i % len2]
    // }
  }
  return ary
}
// @lc code=end

